package com.example.shape;

import org.jbox2d.common.Vec2;

/**
 * Created by Lucas on 17/06/13.
 */
public class Square {

    /**
     * the x coordinate of the origin point of the square
     */
    private float _xCenter;
    /**
     * the x coordinate of the origin point of the square
     */
    private float _yCenter;
    /**
     * The width of the square
     */
    private float _midWidth;
    /**
     * the height of the square
     */
    private float _midHeight;

    /**
     * The constructor of the square
     * @param xBottomLeft the x coordinate of the origin point of the square
     * @param yBottomLeft the y coordinate of the origin point of the square
     * @param midHeight the height of the square
     * @param midWidth the xidth of the square
     */
    public Square(float xBottomLeft, float yBottomLeft, float midHeight, float midWidth){
        _xCenter = xBottomLeft;
        _yCenter = yBottomLeft;
        _midWidth = midWidth;
        _midHeight = midHeight;
    }

    /**
     * return if input point touches the square
     * @param touch the input point
     * @return
     */
    public boolean isTouched(Vec2 touch){
        return isTouched(touch.x, touch.y);
    }

    /**
     * return if the square is touched
     * @param x
     * @param y
     * @return
     */
    public boolean isTouched(float x, float y){
        if (x > _xCenter-_midWidth && x < _xCenter+_midWidth &&
            y > _yCenter-_midHeight && y < _yCenter + _midHeight){
            return true;
        }
        return false;
    }

    /**
     * move the square by the parameters offset
     * @param ofX x offset
     * @param ofY y offset
     */
    public void moveOf(float ofX, float ofY){
        _xCenter += ofX;
        _yCenter += ofY;
    }

    /**
     * move the square to a new location
     * @param toX x of the new location
     * @param toY y of the new location
     */
    public void moveTo(float toX, float toY){
        _xCenter = toX;
        _yCenter = toY;
    }

    public String toString(){
        return "x:"+ _xCenter +" y:"+ _yCenter +" width:"+ _midWidth +" height:"+ _midHeight;
    }

    public float getXCenter(){
        return _xCenter;
    }

    public float getYCenter(){
        return _yCenter;
    }

    public float getMidWidth() {
        return _midWidth;
    }

    public float getMidHeight(){
        return _midHeight;
    }
}
